﻿/*
* Copyright (c) 2010-2012 Tesla Engine Group
* 
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/


using Tesla.Math;

namespace Tesla.Graphics {
    /// <summary>
    /// Represents an omni-directional light source
    /// located at a specific point in world space.
    /// </summary>
    public class PointLight : Light {
        private Vector3 _position;
        private LightType _lightType;

        /// <summary>
        /// Gets or sets the position of the light
        /// in world space.
        /// </summary>
        public Vector3 Position {
            get {
                return _position;
            }
            set {
                _position = value;
            }
        }

        /// <summary>
        /// Gets the light type, in this case LightType.Point.
        /// </summary>
        public override LightType LightType {
            get {
                return _lightType;
            }
        }

        /// <summary>
        /// Creates a new instance of PointLight that
        /// has a positioned at the origin.
        /// </summary>
        public PointLight()
            : base("PointLight") {
                _position = new Vector3();
        }

        /// <summary>
        /// Creates a new PointLight.
        /// </summary>
        /// <param name="pos">Position of the light</param>
        public PointLight(Vector3 pos)
            : base("PointLight") {
                _position = pos;
        }

        /// <summary>
        /// Convienence method for setting the position of this PointLight
        /// in world space
        /// </summary>
        /// <param name="x">X coordinate</param>
        /// <param name="y">Y coordinate</param>
        /// <param name="z">Z coordinate</param>
        public void SetPosition(float x, float y, float z) {
            _position = new Vector3(x, y, z);
        }

        /// <summary>
        /// Serializes this PointLight.
        /// </summary>
        /// <param name="output">Output to be written to</param>
        public override void Write(Content.ISavableWriter output) {
            base.Write(output);
            output.Write("LightType", (int) _lightType);
            output.Write("Position", _position);
        }

        /// <summary>
        /// Deserializes this PointLight.
        /// </summary>
        /// <param name="input">Input to read from</param>
        public override void Read(Content.ISavableReader input) {
            base.Read(input);
            _lightType = (LightType) input.ReadInt();
            _position = input.ReadVector3();
        }
    }
}
